package com.herench.bunch.clinic.utils;

import ca.uhn.hl7v2.model.v24.datatype.CE;
import ca.uhn.hl7v2.model.v24.group.RTB_K13_ROW_DEFINITION;
import ca.uhn.hl7v2.model.v24.message.QBP_Q11;
import ca.uhn.hl7v2.model.v24.message.RTB_K13;
import ca.uhn.hl7v2.model.v24.segment.MSH;
import ca.uhn.hl7v2.model.v24.segment.QPD;
import ca.uhn.hl7v2.model.v24.segment.RDT;
import ca.uhn.hl7v2.parser.DefaultModelClassFactory;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.util.UUID;

public class DeptListOfClinicMessage {

    @Test
    public void test1() throws Exception{
        QBP_Q11 qbp = new QBP_Q11();
        qbp.initQuickstart("200030","REQ", UUID.randomUUID().toString());
        MSH msh = qbp.getMSH();
        msh.getMsh3_SendingApplication().getHd1_NamespaceID().setValue("ZIZH");
        msh.getMsh10_MessageControlID().setValue("200010");
        QPD qpd = qbp.getQPD();
        qpd.getMessageQueryName().getIdentifier().setValue("当日挂号排版查询");
        qpd.getQpd2_QueryTag().setValue("QY");

        CE ce = new CE(qbp);
        ce.getCe1_Identifier().setValue("0001");
        ce.getCe2_Text().setValue("003");

        qpd.getUserParametersInsuccessivefields().setData(ce);
        System.out.println(qbp);
    }


    @Test
    public void test2() throws Exception{
        RTB_K13 rtb = new RTB_K13();
        rtb.initQuickstart("200030","REQ", UUID.randomUUID().toString());
        MSH msh = rtb.getMSH();
        msh.getMsh3_SendingApplication().getHd1_NamespaceID().setValue("ZIZH");
        msh.getMsh10_MessageControlID().setValue("200010");
        RTB_K13_ROW_DEFINITION definition =  rtb.getROW_DEFINITION();
        RDT rdt = new RDT(rtb,new DefaultModelClassFactory());
        CE ce = new CE(rtb);
        ce.getCe1_Identifier().setValue("params");
        ce.getCe2_Text().setValue("003");
        rdt.getColumnValue().setData(ce);
        definition.insertRDT(rdt,0);
        System.out.println(rtb);

    }



    @Test
    public void testXml() throws Exception{
        String str ="<Response>\n" +
                "    <IsSuccessed>0</IsSuccessed>\n" +
                "    <ErrorMsg/>\n" +
                "    <TradeCode>L888</TradeCode>\n" +
                "    <SblwskOut>1|成功|120105199507023013|肖雄|23|1|和仁（天津）科技有限公司|31117553754|1|567&#x6;#</SblwskOut>\n" +
                "</Response>";
        Document doc = new SAXReader().read(new ByteArrayInputStream(str.getBytes()));
        System.out.println(doc);
    }
}
